{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "22771bcc-be48-4bc6-906e-e450568a8734",
   "metadata": {},
   "source": [
    "# Multiple Label Columns with AutoMM\n",
    "\n",
    "AutoGluon MultiModal doesn't natively support multiple label columns. Here's how to handle this challenge in different scenarios."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c3f7d4164a414ef5",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "## Scenario 1: Mutually Exclusive Labels\n",
    "\n",
    "When your label columns are mutually exclusive (only one can be true at a time):\n",
    "\n",
    "```python\n",
    "# Preprocessing: Convert multiple columns to single label\n",
    "def combine_labels(row, label_columns):\n",
    "    for label in label_columns:\n",
    "        if row[label] == 1:\n",
    "            return label\n",
    "    return 'none'\n",
    "\n",
    "# Apply transformation\n",
    "df['combined_label'] = df.apply(lambda row: combine_labels(row, label_columns), axis=1)\n",
    "\n",
    "# For MultiModal\n",
    "from autogluon.multimodal import MultiModalPredictor\n",
    "predictor = MultiModalPredictor(label='combined_label').fit(df)\n",
    "\n",
    "# Postprocessing (if needed): Convert predictions back to multiple columns\n",
    "predictions = predictor.predict(test_data)\n",
    "for label in label_columns:\n",
    "    test_data[f'{label}'] = (predictions == label).astype(int)\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "99c4fe3a-3acd-4db1-af27-e8aca839bb66",
   "metadata": {},
   "source": [
    "## Scenario 2: Non-Mutually Exclusive Labels\n",
    "\n",
    "When your label columns are NOT mutually exclusive (multiple can be true simultaneously):\n",
    "\n",
    "```python\n",
    "# Define label columns\n",
    "label_columns = ['label1', 'label2', 'label3']\n",
    "predictors = {}\n",
    "\n",
    "# For each label column\n",
    "for label in label_columns:\n",
    "    # Create copy without other label columns\n",
    "    train_df = df.drop(columns=[l for l in label_columns if l != label])\n",
    "    \n",
    "    # For MultiModal\n",
    "    from autogluon.multimodal import MultiModalPredictor\n",
    "    predictors[label] = MultiModalPredictor(label=label).fit(train_df)\n",
    "\n",
    "# Predict with each model\n",
    "for label in label_columns:\n",
    "    # Remove all label columns from test features\n",
    "    test_features = test_data.drop(columns=label_columns)\n",
    "    test_data[f'pred_{label}'] = predictors[label].predict(test_features)\n",
    "```\n",
    "\n",
    "Note that you need to ensure other label columns are excluded from features, and adjust the time_limit parameter accordingly. If you have N label columns, consider allocating your total available time divided by N for each predictor"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "48e372691fe7f9c0",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "## Customization\n",
    "To learn how to customize AutoMM, please refer to [Customize AutoMM](../advanced_topics/customization.ipynb)."
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
